/**
 * TO BE DETERMINED
 */
package org.eichar.server.database;

import static org.eichar.server.database.DatabaseAccess.COL_WORD_ID;
import static org.eichar.server.database.DatabaseAccess.COL_WORD_WORD;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.eichar.client.shared.Word;

/**
 * Wraps word and adds db specific information.
 * 
 * @author Jesse
 */
class DBWord {

    private final long wordIndex;

    final Word word;

    public DBWord(String langCode, ResultSet results) throws SQLException {
        word = Word.get(results.getString(COL_WORD_WORD), langCode);

        wordIndex = results.getLong(COL_WORD_ID);
    }

    /**
     * @see org.eichar.client.shared.Word#getLanguageCode()
     */
    public String getLanguageCode() {
        return word.getLanguageCode();
    }

    /**
     * @see org.eichar.client.shared.Word#getWord()
     */
    public String getWord() {
        return word.getWord();
    }

    /**
     * @see org.eichar.client.shared.Word#toString()
     */
    public String toString() {
        return word.toString();
    }

    /**
     * @return the wordIndex
     */
    public final long getWordIndex() {
        return wordIndex;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((word == null) ? 0 : word.hashCode());
        result = (int) (PRIME * result + wordIndex);
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final DBWord other = (DBWord) obj;
        if (word == null) {
            if (other.word != null)
                return false;
        } else if (!word.equals(other.word))
            return false;
        if (wordIndex != other.wordIndex)
            return false;
        return true;
    }

}
